package org.jzentest.dependency;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

import org.objectweb.asm.ClassReader;
import org.objectweb.asm.depend.DependencyVisitor;

public class ClassAnalyzer {
	private String exclude;
	private String testType;
	
	public ClassAnalyzer(String testType, String exclude) {
		this.testType = testType;
		this.exclude = exclude;
	}
	
	public TestDependencies parse(File f) throws FileNotFoundException, IOException {
        DependencyVisitor v = new DependencyVisitor(testType, exclude);

        ClassReader classReader = new ClassReader(new FileInputStream(f));
		classReader.accept(v, 0);
		
		String selfType = classReader.getClassName().replace("/", ".");
		v.getTypes().remove(selfType);

		if (v.getTypes().remove(testType)) {
			return new TestDependencies(selfType, v.getTypes());
		} else {
			return null;
		}
	}
}
